/*
 * CHMainUI.java
 *
 * Created on __DATE__, __TIME__
 */

package com.kylinhunter.ch.main;

 
import java.util.ArrayList;
 
import java.util.List;
 

import org.springframework.beans.factory.InitializingBean;

 
import com.kylinhunter.ch.language.LangChangeListener;
import com.kylinhunter.ch.language.ResourceManager;
 
import com.kylinhunter.ch.system.CHSystem;
 
import com.kylinhunter.ui.common.KHDesktop;
import com.kylinhunter.ui.common.action.ExcueteAction;
import com.kylinhunter.ui.common.plugin.Plugin;
import com.kylinhunter.ui.common.plugin.PluginMenu;
import com.kylinhunter.ui.common.plugin.PluginMenuItem;

/**
 *
 * @author  __USER__
 */
public class CHMainUI extends BaseMainFrame implements LangChangeListener,
		InitializingBean {


	private CHMainUIAction chMainUIAction = null;
	

	/** Creates new form CHMainUI */
	public CHMainUI() {
		initComponents();
	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		lookAndFeelButtonGroup = new javax.swing.ButtonGroup();
		chMenuBar = new javax.swing.JMenuBar();
		systemMenu = new javax.swing.JMenu();
		changeLanguageMenuItem = new javax.swing.JMenuItem();
		exitMenuItem = new javax.swing.JMenuItem();
		lookAndFeelMenu = new javax.swing.JMenu();
		radioButtonMenuItem_Metal = new javax.swing.JRadioButtonMenuItem();
		radioButtonMenuItem_Windows = new javax.swing.JRadioButtonMenuItem();
		radioButtonMenuItem_Office2003 = new javax.swing.JRadioButtonMenuItem();
		helpMenu = new javax.swing.JMenu();
		aboutMenuItem = new javax.swing.JMenuItem();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent evt) {
				formWindowClosing(evt);
			}
		});

		systemMenu.setText("System");

		changeLanguageMenuItem.setText("To Chinese");
		changeLanguageMenuItem
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						changeLanguageMenuItemActionPerformed(evt);
					}
				});
		systemMenu.add(changeLanguageMenuItem);

		exitMenuItem.setText("Exit");
		exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitMenuItemActionPerformed(evt);
			}
		});
		systemMenu.add(exitMenuItem);

		chMenuBar.add(systemMenu);

		lookAndFeelMenu.setText("LookAndFeel");

		lookAndFeelButtonGroup.add(radioButtonMenuItem_Metal);
		radioButtonMenuItem_Metal.setSelected(true);
		radioButtonMenuItem_Metal.setText("Metal");
		lookAndFeelMenu.add(radioButtonMenuItem_Metal);

		lookAndFeelButtonGroup.add(radioButtonMenuItem_Windows);
		radioButtonMenuItem_Windows.setSelected(true);
		radioButtonMenuItem_Windows.setText("Windows");
		lookAndFeelMenu.add(radioButtonMenuItem_Windows);

		lookAndFeelButtonGroup.add(radioButtonMenuItem_Office2003);
		radioButtonMenuItem_Office2003.setSelected(true);
		radioButtonMenuItem_Office2003.setText("Office2003");
		lookAndFeelMenu.add(radioButtonMenuItem_Office2003);

		chMenuBar.add(lookAndFeelMenu);

		helpMenu.setText("Help");

		aboutMenuItem.setText("About");
		helpMenu.add(aboutMenuItem);

		chMenuBar.add(helpMenu);

		setJMenuBar(chMenuBar);

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void formWindowClosing(java.awt.event.WindowEvent evt) {
		// TODO add your handling code here:		
//		this.chMainUIAction.saveConfig(this);
	 
			ExcueteAction.execute(chMainUIAction,this,chMainUIAction.Action_SaveConfig);
		 

	}

	private void changeLanguageMenuItemActionPerformed(
			java.awt.event.ActionEvent evt) {
//		this.chMainUIAction.changeLanguage(this);
	 
			ExcueteAction.execute(chMainUIAction,this,chMainUIAction.Action_ChangeLanguage);
		 

	}

	private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		 
	 
			ExcueteAction.execute(chMainUIAction,this,chMainUIAction.Action_SaveConfig);
		 
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new CHMainUI().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JMenuItem aboutMenuItem;
	private javax.swing.JMenuBar chMenuBar;
	private javax.swing.JMenuItem changeLanguageMenuItem;
	private javax.swing.JMenuItem exitMenuItem;
	private javax.swing.JMenu helpMenu;
	private javax.swing.ButtonGroup lookAndFeelButtonGroup;
	private javax.swing.JMenu lookAndFeelMenu;
	private javax.swing.JRadioButtonMenuItem radioButtonMenuItem_Metal;
	private javax.swing.JRadioButtonMenuItem radioButtonMenuItem_Office2003;
	private javax.swing.JRadioButtonMenuItem radioButtonMenuItem_Windows;
	private javax.swing.JMenu systemMenu;

	// End of variables declaration//GEN-END:variables
	@Override
	public void updateResource(ResourceManager resourceManager) {
		// TODO Auto-generated method stub

		this.systemMenu.setText(resourceManager.getString(ResourceManager.SYS_RESOURCE_FILE,"main.system"));
		this.aboutMenuItem.setText(resourceManager.getString(ResourceManager.SYS_RESOURCE_FILE,"main.about"));
		this.exitMenuItem.setText(resourceManager.getString(ResourceManager.SYS_RESOURCE_FILE,"main.exit"));
		this.helpMenu.setText(resourceManager.getString(ResourceManager.SYS_RESOURCE_FILE,"main.help"));
		this.changeLanguageMenuItem.setText(resourceManager
				.getString(ResourceManager.SYS_RESOURCE_FILE,"main.changeLanguage"));
		this.radioButtonMenuItem_Windows.setText(resourceManager
				.getString(ResourceManager.SYS_RESOURCE_FILE,"main.radioButtonMenuItem_Windows"));
		this.radioButtonMenuItem_Office2003.setText(resourceManager
				.getString(ResourceManager.SYS_RESOURCE_FILE,"main.radioButtonMenuItem_Office2003"));
		this.radioButtonMenuItem_Metal.setText(resourceManager
				.getString(ResourceManager.SYS_RESOURCE_FILE,"main.radioButtonMenuItem_Metal"));
		this.radioButtonMenuItem_Windows.setActionCommand("Windows");
		this.radioButtonMenuItem_Office2003.setActionCommand("Office2003");
		this.radioButtonMenuItem_Metal.setActionCommand("Metal");	 
	 
		this.lookAndFeelMenu.setText(resourceManager
				.getString(ResourceManager.SYS_RESOURCE_FILE,"main.lookAndFeelMenu"));
		for (PluginMenu m : this.getPluginMenu()) {
			m.setText(resourceManager.getString(m.getResource(),m.getName()));
		}
		for (PluginMenuItem mi : this.getPluginMenuItem()) {
			mi.setText(resourceManager.getString(mi.getResource(),mi.getName()));
		}

	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		 
	}	 

	public CHMainUIAction getChMainUIAction() {
		return chMainUIAction;
	}

	public void setChMainUIAction(CHMainUIAction chMainUIAction) {
		this.chMainUIAction = chMainUIAction;
	}

	public javax.swing.JRadioButtonMenuItem getRadioButtonMenuItem_Metal() {
		return radioButtonMenuItem_Metal;
	}

	public void setRadioButtonMenuItem_Metal(
			javax.swing.JRadioButtonMenuItem radioButtonMenuItemMetal) {
		radioButtonMenuItem_Metal = radioButtonMenuItemMetal;
	}

	public javax.swing.JRadioButtonMenuItem getRadioButtonMenuItem_Office2003() {
		return radioButtonMenuItem_Office2003;
	}

	public void setRadioButtonMenuItem_Office2003(
			javax.swing.JRadioButtonMenuItem radioButtonMenuItemOffice2003) {
		radioButtonMenuItem_Office2003 = radioButtonMenuItemOffice2003;
	}

	public javax.swing.JRadioButtonMenuItem getRadioButtonMenuItem_Windows() {
		return radioButtonMenuItem_Windows;
	}

	public void setRadioButtonMenuItem_Windows(
			javax.swing.JRadioButtonMenuItem radioButtonMenuItemWindows) {
		radioButtonMenuItem_Windows = radioButtonMenuItemWindows;
	}

	
	public javax.swing.JMenuBar getChMenuBar() {
		return chMenuBar;
	}

	public void setChMenuBar(javax.swing.JMenuBar chMenuBar) {
		this.chMenuBar = chMenuBar;
	}

	@Override
	public void chInit() {
		// TODO Auto-generated method stub
		 ExcueteAction.execute(chMainUIAction,this,chMainUIAction.Action_Init);
	}

}